<?php 
namespace app\models;

use think\Model;
use app\models\User;

class UserTree extends Model
{
    protected $pk = 'id';
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'created';
    protected $updateTime = 'updated';

    public function child($parent_id)
    {
        $parent = User::field('id,parent_id')->get($parent_id);
        if($parent){
            $b = $this->where('uid',$parent_id)->setInc('child',1);
            $this->child($parent['parent_id']);
        }
    }

}